package com.imau.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        //设置编码
        request.setCharacterEncoding("UTF-8");
        //获取请求参数
        String username = request.getParameter("username");

        String password = request.getParameter("password");


        if("admin".equals(username) && "123456".equals(password))
        {
            //共享数据 放到request域中 属性名 属性值
             request.setAttribute("username",username);
            //请求转发，浏览器地址不变跳转到后台，超链接
            request.getRequestDispatcher("/welcom").forward(request,response);
        }else {


            //跳转到登录页面，给个提示错误
        }

    }
}
